<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
%>
<html>
    <head>
        <title>Log.jsp</title>
        <link href="<%=path%>/bootstrap/css/bootstrap.css" rel="stylesheet">
        <script src="<%=path%>/jquery/jquery-3.3.1.js"></script>
        <script src="<%=path%>/jquery/jquery.cookie.js"></script>
        <script src="<%=path%>/bootstrap/js/bootstrap.js"></script>
    </head>
    <body>

        <div class="container">

            <table class="table" id="myTable">
                <div class="form-group mb-2">
                    <input type="text" id="searchId" placeholder="请输入用户Id名称">
                    <a id="btn" class="btn btn-info btn-sm mb-1" href="javascript:;" onclick="searchLog()">搜索</a>
                </div>
                <thead>
                <tr>
                    <th>序号</th>
                    <th>用户Id</th>
                    <th>用户姓名</th>
                    <th>用户电话</th>
                    <th>用户邮箱</th>
                    <th>用户地址</th>
                    <th>物品Id</th>
                    <th>物品名称</th>
                    <th>用户操作</th>
                    <th>时间</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${pageLike.list}" var="one">
                    <tr>
                        <td>${one.logId}</td>
                        <td>${one.users.id}</td>
                        <td>${one.users.name}</td>
                        <td>${one.users.phone}</td>
                        <td>${one.users.email}</td>
                        <td>${one.users.address}</td>
                        <td>${one.goods.goodsId}</td>
                        <td>${one.goods.goodsName}</td>
                        <td>${one.operate}</td>
                        <td>${one.time}</td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
            <div>
                <button class="btn btn-primary" onclick="firstPage()">首页</button>
                <button class="btn btn-primary" onclick="prevPage()">上一页</button>
                <button class="btn btn-primary" onclick="nextPage()">下一页</button>
                <button class="btn btn-primary" onclick="lastPage()">尾页</button>
                <span> 当前第${pageLike.currentPage}页，共${pageLike.totalPage}页，共${pageLike.totalSize}条记录 </span>
            </div>
        </div>

        <script>
            $("#searchId").val($.cookie("input_value"));
            var pageSize = ${pageLike.pageSize};
            var pageNumber = ${pageLike.currentPage};
            var totalPage = ${pageLike.totalPage};

            function firstPage() {
                if(pageNumber != 1){
                    pageNumber = 1;
                    pageChange();
                }
            }
            function prevPage() {
                if(pageNumber > 1){
                    pageNumber--;
                    pageChange();
                }
            }
            function nextPage() {
                if(pageNumber < totalPage){
                    pageNumber ++;
                    pageChange();
                }
            }
            function lastPage() {
                if(pageNumber != totalPage){
                    pageNumber = totalPage;
                    pageChange();
                }
            }

            function searchLog(){
                var search = $("#searchId").val();
                $.cookie("input_value", search);
                pageNumber = 1;
                pageChange();
            }
            function pageChange() {
                window.location.href = "${pageContext.request.contextPath}/log/getLogAll?PageNumber=" +pageNumber+ "&id=" +$("#searchId").val();
            }


        </script>

    </body>
</html>
